package top.tsyz.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.tsyz.entity.Admin;
import top.tsyz.service.IAdminService;

import java.util.List;

/**
 * AdminController控制器
 */
@RestController
@RequestMapping("/api/admins")
@Api(tags = "Admin管理接口")
public class AdminController {

    @Autowired
    private IAdminService iadminservice;

    @GetMapping("/list")
    @ApiOperation("获取所有Admin")
    public List<Admin> list() {
        return iadminservice.list();
    }

    @GetMapping("/{id}")
    @ApiOperation("根据ID获取Admin")
    public Admin getById(@PathVariable Long id) {
        return iadminservice.getById(id);
    }

    @PostMapping
    @ApiOperation("新增Admin")
    public boolean save(@RequestBody Admin admin) {
        return iadminservice.save(admin);
    }

    @PutMapping
    @ApiOperation("更新Admin")
    public boolean update(@RequestBody Admin admin) {
        return iadminservice.updateById(admin);
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除Admin")
    public boolean delete(@PathVariable Long id) {
        return iadminservice.removeById(id);
    }
}
